package com.newbye.files
{
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;

	public class PanelTemplateFactory
	{
		public static function create(className:String, parentClass:String):*
		{
			var contents:String = 
				  "package"
			"\r" + "{"
			"\r" + 	"\r"
			"\r" + 	getImportString(parentClass)
			"\r" + 	"\tpublic class" + className + "extends" + parentClass
			"\r" + 	"{"
			"\r" + 	"\r"
			"\r" +		"public function " + className + "()"
			"\r" +		"{"
			"\r" +		"\t"
			"\r" +		"\tsuper();"
			"\r" +		"}"
			"\r" + 	"}"
			"\r" + "}";
				
				
				;
				return contents;
		}
		
		private function createConfigClass():String
		{
			var rstr:String = "";
			
			
			return rstr;
		}
		
		private static function getImportString(parentClassName:String):String
		{
			var rs:String = "\timport flash.display.Sprite;\r";
			
			return "";
		}
		
		
		public static function createByTemplate1(className:String, parentClass:String):String
		{
			var rstr:String = "";
			
			rstr = getTemplate1();
			rstr = rstr.replace(FileTemplateConst.ClassName, className);
			rstr = rstr.replace(FileTemplateConst.SuperClassName, parentClass);
			rstr = rstr.replace(FileTemplateConst.ImportList, getImportString(parentClass));
			
			return rstr;
		}
		
		private static function getTemplate1():String
		{
			var cstr:String = "";
			var f:File = new File(File.applicationDirectory.nativePath + "/templates/Template1.as");
			if(f.exists)
			{
				var fs:FileStream = new FileStream();
				fs.open(f, FileMode.READ);
				fs.position = 0;
				cstr = fs.readUTFBytes(fs.bytesAvailable);
				fs.close();
			}
			
			return cstr;
		}
	}
}